package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Activity;
import com.qk.mapper.ActivityMapper;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;
    @Override
    public PageResult<Activity> listActivity(String name, Integer channel, Integer type, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Activity> activityList = activityMapper.listActivity(name, channel, type);
        Page<Activity> page1 = (Page<Activity>) activityList;
        return new PageResult<>(page1.getTotal(), page1.getResult());
    }

    @Override
    public void deleteById(Integer id) {
        activityMapper.deleteById(id);
    }

    @Override
    public void addActivity(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.addActivity(activity);
    }

    @Override
    public Activity getById(Integer id) {
        return activityMapper.getById(id);
    }

    @Override
    public void updateActivity(Activity activity) {
        activityMapper.updateActivity(activity);
    }

    @Override
    public List<Activity> listActivityByType(Integer type) {
        return activityMapper.listActivityByType(type);
    }
}
